home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-07-14 | 47.6 KB | 1,485 lines | [TEXT/CWIE] |
- /*************************************************************************************
-
- File: DialogUtilities.cp
-
- Copyright © 1996, 1997, 1998 Apple Computer, Inc., All Rights Reserved
-
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- *************************************************************************************/
- #ifndef __PALETTES__
- #include <Palettes.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- // nothing here should be speed dependent
- #if __MWERKS__
- #pragma optimize_for_size on
- #endif
-
- #include "DialogUtils.h"
-
- // debug mode turns on assertions
- #ifndef DEBUG
- #define DEBUG 0
- #endif
-
- /*
- * safe turns on extra (theoretically unneeded) error checking
- * all the errors that it handles are ones that would generate assertions
- * it is a saftey vs code size (about 5k for all the functions) decision
- */
-
- #ifndef SAFE
- #define SAFE 1
- #endif
-
- #ifdef UNIVERSAL_INTERFACES_VERSION
- typedef UInt32 DelayType;
- #else
- typedef SInt32 DelayType;
- #endif
-
- /*
- *
- * Here are our assertion style macros. We use these to do the parameter
- * validation and extra error checking (the sort of things the toolbox
- * doesn't do and that really aren't required. (example making sure
- * when you animate a button click that the item is actually a button).
- *
- */
-
- #if DEBUG
- #define DUASSERT_RETVAL(test,str,err) {if(!(test)){DebugStr("\p" #str ); return (err);}}
- #define DUASSERT_RET(test,str) {if(!(test)){DebugStr("\p" #str ); return;}}
- #define DUASSERT(test, str) {if(!(test)){DebugStr("\p" #str);}}
- #elif SAFE
- #define DUASSERT_RETVAL(test,str,err) {if(!(test)){ return (err);}}
- #define DUASSERT_RET(test,str) {if(!(test)){ return; }}
- #define DUASSERT(test, str) ((void)0)
- #else
- #define DUASSERT_RETVAL(test,str,err) ((void)0)
- #define DUASSERT_RET(test,str) ((void)0)
- #define DUASSERT(test, str) ((void)0)
- #endif
-
- pascal void OKUserProc(DialogPtr inDialog, DialogItemIndex inItem);
- pascal void PrimaryGroupUserProc(DialogPtr inDialog, DialogItemIndex inItem);
- pascal void SecondaryGroupUserProc(DialogPtr inDialog, DialogItemIndex inItem);
- pascal Boolean ModernStdFilterProc(DialogPtr inDialog, EventRecord *inEvent, DialogItemIndex *inItem);
-
- #if GENERATINGCFM
- RoutineDescriptor OKUserProcRD = BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo, OKUserProc);
- RoutineDescriptor SecondaryGroupUserProcRD = BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo, SecondaryGroupUserProc);
- RoutineDescriptor PrimaryGroupUserProcRD = BUILD_ROUTINE_DESCRIPTOR(uppUserItemProcInfo, PrimaryGroupUserProc);
- RoutineDescriptor ModernStdFilterProcRD = BUILD_ROUTINE_DESCRIPTOR(uppModalFilterProcInfo, ModernStdFilterProc);
-
- UserItemUPP OKUserProcUPP = &OKUserProcRD;
- UserItemUPP SecondaryGroupUserProcUPP = &SecondaryGroupUserProcRD;
- UserItemUPP PrimaryGroupUserProcUPP = &PrimaryGroupUserProcRD;
- ModalFilterUPP ModernStdFilterProcUPP = &ModernStdFilterProcRD;
- #else
- UserItemUPP OKUserProcUPP = OKUserProc;
- UserItemUPP SecondaryGroupUserProcUPP = SecondaryGroupUserProc;
- UserItemUPP PrimaryGroupUserProcUPP = PrimaryGroupUserProc;
- ModalFilterUPP ModernStdFilterProcUPP = ModernStdFilterProc;
- #endif
-
- /* =============================================================================
- * OKUserProc (internal)
- *
- * Draws the user item used for framing the OK button. The user item should
- * be four pixels larger than the OK button in each direction.
- * ========================================================================== */
-
- pascal void OKUserProc(
- DialogPtr inDialog,
- DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "OKUserProc inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "OKUserProc inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "OKUserProc inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "OKUserProc inItem <= 0");
-
- Rect rect;
-
- DialogItem_GetRect(inDialog, inItem, &rect);
-
- PenSize(3, 3);
- FrameRoundRect(&rect, 16, 16);
- PenSize(1, 1);
- }
-
- /* =============================================================================
- * PrimaryGroupUserProc (internal)
- *
- * ========================================================================== */
-
- pascal void PrimaryGroupUserProc(
- DialogPtr inDialog,
- DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "PrimaryGroupUserProc inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "PrimaryGroupUserProc inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "PrimaryGroupUserProc inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "PrimaryGroupUserProc inItem <= 0");
-
- Rect rect;
- GScActiveType active = kGSInactive;
-
- DialogItem_GetRect(inDialog, inItem, &rect);
- if (FrontWindow() == inDialog) { active = kGSActive; }
-
- GScGroupBox_PrimarySimple_Draw(&rect, active);
- }
-
- /* =============================================================================
- * SecondaryGroupProc (internal)
- *
- * ========================================================================== */
-
- pascal void SecondaryGroupUserProc(
- DialogPtr inDialog,
- DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "SecondaryGroupUserProc inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "SecondaryGroupUserProc inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "SecondaryGroupUserProc inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "SecondaryGroupUserProc inItem <= 0");
-
- Rect rect;
- GScActiveType active = kGSInactive;
-
- DialogItem_GetRect(inDialog, inItem, &rect);
- if (FrontWindow() == inDialog) { active = kGSActive; }
-
- GScGroupBox_SecondarySimple_Draw(&rect, active);
- }
-
-
- pascal Boolean ModernStdFilterProc(
- DialogPtr inDialog,
- EventRecord* inEvent,
- DialogItemIndex* outItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "ModernStdFilterProc inDialog == nil", false);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "ModernStdFilterProc inDialog is not a dialog", false);
- DUASSERT_RETVAL(inEvent != nil, "ModernStdFilterProc inEvent == nil", false);
- DUASSERT_RETVAL(outItem != nil, "ModernStdFilterProc outItem == nil", false);
-
- Boolean handled = false;
- *outItem = 0;
-
- switch(inEvent->what)
- {
- case keyDown:
- handled = FilterKeyEvent(inDialog, inEvent, outItem);
- break;
- }
-
- // if did not handled it let the standard filter proc handled it
- if (!handled)
- {
- handled = StdFilterProc(inDialog, inEvent, outItem);
- }
-
- return handled;
- }
-
-
- static inline Boolean CheckKeyMap(unsigned char *keyMap, UInt32 scanCode)
- {
- return ((keyMap[scanCode >> 3]) >> (scanCode & 7) & 1);
- }
-
- EventModifiers GetKeyModifiers(void)
- {
- UInt16 modifiers = 0;
- UInt8 keyMap[16];
-
- // bit positions in the keymap of the modifier keys
- enum
- {
- kCommandKeyCode = 55,
- kLeftShiftKeyCode = 56,
- kLeftOptionKeyCode = 58,
- kLeftControlKeyCode = 59,
-
- kRightShiftKeyCode = 60,
- kRightOptionKeyCode = 61,
- kRightControlKeyCode = 62
- };
-
- GetKeys ((long *) keyMap);
-
- if (CheckKeyMap(keyMap, kCommandKeyCode)) { modifiers |= cmdKey; }
- if (CheckKeyMap(keyMap, kLeftShiftKeyCode)) { modifiers |= shiftKey; }
- if (CheckKeyMap(keyMap, kLeftOptionKeyCode)) { modifiers |= optionKey; }
- if (CheckKeyMap(keyMap, kLeftControlKeyCode)) { modifiers |= controlKey; }
-
- if (CheckKeyMap(keyMap, kRightShiftKeyCode)) { modifiers |= rightShiftKey; modifiers |= shiftKey; }
- if (CheckKeyMap(keyMap, kRightOptionKeyCode)) { modifiers |= rightOptionKey; modifiers |= optionKey; }
- if (CheckKeyMap(keyMap, kRightControlKeyCode)) { modifiers |= rightControlKey; modifiers |= controlKey; }
-
- return modifiers;
- }
-
- Boolean KeyEventOK(EventRecord *inEvent)
- {
- DUASSERT_RETVAL(inEvent != nil, "KeyEventOK inEvent is nil", false);
- DUASSERT_RETVAL(keyDown == inEvent->what, "KeyEventOK passed something other than keyDown", false);
-
- Boolean OKEvent = false;
-
- switch(inEvent->message & charCodeMask)
- {
- case 13: // enterKey
- case 3: // returnKey
- OKEvent = true;
- break;
- }
-
- return OKEvent;
- }
-
- Boolean KeyEventCancel(EventRecord *inEvent)
- {
- DUASSERT_RETVAL(inEvent != nil, "KeyEventCancel inEvent is nil", false);
- DUASSERT_RETVAL(keyDown == inEvent->what, "KeyEventCancel passed something other than keyDown", false);
-
- Boolean cancelEvent = false;
-
- switch(inEvent->message & charCodeMask)
- {
- case '.': // command period
- if (inEvent->modifiers & cmdKey) { cancelEvent = true; }
- break;
-
- case 27: // escape or clear
- cancelEvent = true;
- break;
- }
-
- return cancelEvent;
- }
-
- Boolean FilterKeyEvent(DialogPtr inDialog, EventRecord *inEvent, DialogItemIndex *outItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "FilterKeyEvent inDialog == nil", 0);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "FilterKeyEvent inDialog is not a dialog", 0);
- DUASSERT_RETVAL(outItem != nil, "FilterKeyEvent outItem is nil", 0);
- DUASSERT_RETVAL(inEvent != nil, "FilterKeyEvent inEvent is nil", 0);
- DUASSERT_RETVAL(keyDown == inEvent->what, "FilterKeyEvent passed something other than keyDown", 0);
-
- Boolean handled = false; // assume we won't handle it
- DialogItemIndex itemHit = 0; // assume we didn't hit any item
-
- if (KeyEventOK(inEvent))
- {
- itemHit = GetDialogDefaultItem(inDialog);
- }
- else if (KeyEventCancel(inEvent))
- {
- itemHit = GetDialogCancelItem(inDialog);
- }
-
- if (itemHit != 0)
- {
- DialogItem_AnimateButtonClick(inDialog, itemHit);
-
- *outItem = itemHit;
- handled = true;
- }
-
- return handled;
- }
-
- void DialogItem_SetUserProc(DialogRef inDialog, DialogItemIndex inItem, const UserItemUPP inUserProc)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetUserProc inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetUserProc inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetUserProc inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetUserProc inItem <= 0");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RET(isUserType(type), "DialogItem_SetUserProc item not a user item");
-
- SetDialogItem(inDialog, inItem, type, (Handle) inUserProc, &rect);
- }
-
- void DialogItem_SetOKUserProc(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetOKUserProc inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetOKUserProc inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetOKUserProc inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetOKUserProc inItem <= 0");
-
- DialogItem_SetUserProc(inDialog, inItem, OKUserProcUPP);
- }
-
- void DialogItem_SetPrimaryGroupUserProc(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetPrimaryGroupUserProc inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetPrimaryGroupUserProc inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetPrimaryGroupUserProc inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetPrimaryGroupUserProc inItem <= 0");
-
- DialogItem_SetUserProc(inDialog, inItem, PrimaryGroupUserProcUPP);
- }
-
- void DialogItem_SetSecondaryGroupUserProc(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetSecondaryGroupUserProc inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetSecondaryGroupUserProc inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetSecondaryGroupUserProc inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetSecondaryGroupUserProc inItem <= 0");
-
- DialogItem_SetUserProc(inDialog, inItem, SecondaryGroupUserProcUPP);
- }
-
- /*
- *
- * DialogItem_GetControl
- *
- */
-
- typedef struct {
- MenuHandle mHandle;
- short mID;
- } PopupData, **PopupDataHandle;
-
- MenuHandle DialogItem_GetPopupMenu(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "DialogItem_GetPopupMenu inDialog == nil", nil);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "DialogItem_GetPopupMenu inDialog is not a dialog",nil);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inItem, "DialogItem_GetPopupMenu inItem > CountDITL(inDialog)", nil);
- DUASSERT_RETVAL(inItem > 0, "DialogItem_GetPopupMenu inItem <= 0", nil);
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RETVAL(isControlType(type), "DialogItem_GetPopupMenu type was not a control type", nil);
- DUASSERT_RETVAL(handle != nil, "DialogItem_GetPopupMenu handle was nil", nil);
- DUASSERT_RETVAL(*handle != nil, "DialogItem_GetPopupMenu handle was purged", nil);
-
- MenuHandle menuHandle = nil;
-
- ControlHandle controlHandle = (ControlHandle) handle;
- ControlPtr controlPtr = *controlHandle;
- PopupDataHandle popupHandle = (PopupDataHandle) controlPtr->contrlData;
- PopupData *popupPtr = *popupHandle;
-
- menuHandle = popupPtr->mHandle;
-
- return menuHandle;
- }
-
- void DialogItem_SetPopupMenu(DialogRef inDialog, DialogItemIndex inItem, MenuHandle inMenuHandle)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetPopupMenu inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetPopupMenu inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetPopupMenu inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetPopupMenu inItem <= 0");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RET(isControlType(type), "DialogItem_SetPopupMenu type was not a control type");
- DUASSERT_RET(handle != nil, "DialogItem_SetPopupMenu handle was nil");
- DUASSERT_RET(*handle != nil, "DialogItem_SetPopupMenu handle was purged");
-
- ControlHandle controlHandle = (ControlHandle) handle;
- ControlPtr controlPtr = *controlHandle;
- PopupDataHandle popupHandle = (PopupDataHandle) controlPtr->contrlData;
- PopupData *popupPtr = *popupHandle;
-
- popupPtr->mHandle = inMenuHandle;
- }
-
- ControlHandle DialogItem_GetControl(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "DialogItem_GetControl inDialog == nil", nil);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "DialogItem_GetControl inDialog is not a dialog",nil);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inItem, "DialogItem_GetControl inItem > CountDITL(inDialog)", nil);
- DUASSERT_RETVAL(inItem > 0, "DialogItem_GetControl inItem <= 0", nil);
-
- short type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RETVAL(isControlType(type), "DialogItem_GetControl not a control item", nil);
- DUASSERT_RETVAL(handle != nil, "DialogItem_GetControl handle was nil", nil);
- DUASSERT_RETVAL(*handle != nil, "DialogItem_GetControl handle was purged", nil);
-
- ControlHandle controlHandle = nil;
-
- controlHandle = (ControlHandle) handle;
-
- return controlHandle;
- }
-
-
- void DialogItem_HiliteControl(DialogRef inDialog, DialogItemIndex inItem, ControlPartCode hiliteState)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_HiliteControl inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_HiliteControl inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_HiliteControl inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_HiliteControl inItem <= 0");
-
- ControlHandle control;
-
- control = DialogItem_GetControl(inDialog, inItem);
-
- DUASSERT_RET(control != nil, "DialogItem_HiliteControl control was nil");
-
- HiliteControl(control, hiliteState);
- }
-
- void DialogItem_AnimateButtonClick(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_AnimateButtonClick inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_AnimateButtonClick inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_AnimateButtonClick inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_AnimateButtonClick inItem <= 0");
-
- short type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RET(isButtonType(type), "DialogItem_AnimateButtonClick not a button item");
- DUASSERT_RET(handle != nil, "DialogItem_AnimateButtonClick handle == nil");
- DUASSERT_RET(*handle != nil, "DialogItem_AnimateButtonClick handle was purged");
-
- const UInt32 kDelayAmt = 8;
- DelayType finalTicks;
-
- ControlHandle controlHandle = (ControlHandle) handle;
-
- HiliteControl(controlHandle, 1);
- Delay(kDelayAmt, &finalTicks);
- HiliteControl(controlHandle, 0);
- }
-
- /*
- *
- *
- * Disable/Enable dialog items
- *
- *
- */
-
- void DialogItem_Disable(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_Disable inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_Disable inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_Disable inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_Disable inItem <= 0");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
- SetDialogItem(inDialog, inItem, type | kItemDisableBit, handle, &rect);
-
- if (isControlType(type))
- {
- DUASSERT_RET(handle != nil, "DialogItem_Disable item is control but handle is nil");
-
- ControlHandle controlHandle = (ControlHandle) handle;
-
- HiliteControl(controlHandle, kControlInactivePart);
- }
- }
-
- void DialogItem_Enable(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_Enable inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_Enable inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_Enable inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_Enable inItem <= 0");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
- SetDialogItem(inDialog, inItem, type & ~kItemDisableBit, handle, &rect);
-
- if (isControlType(type))
- {
- DUASSERT_RET(handle != nil, "DialogItem_Disable item is control but handle is nil");
-
- ControlHandle controlHandle = (ControlHandle) handle;
-
- HiliteControl(controlHandle, kControlNoPart);
- }
- }
-
- /*
- *
- *
- * Getting/Setting dialog item text
- *
- */
-
- void DialogItem_GetText(DialogRef inDialog, DialogItemIndex inItem, Str255 outText)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_GetText inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_GetText inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_GetText inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_GetText inItem <= 0");
- DUASSERT_RET(outText != nil, "DialogItem_GetText outText != nil");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- Boolean staticTextItem = isStaticTextType(type);
- Boolean editTextItem = isEditTextType(type);
- Boolean controlItem = isControlType(type);
-
- DUASSERT_RET(staticTextItem || editTextItem || controlItem, "DialogItem_GetText item wrong type");
- DUASSERT_RET(handle != nil, "DialogItem_GetText item handle = nil");
- DUASSERT_RET(*handle != nil, "DialogItem_GetText item handle was purged");
-
- outText[0] = 0; // assume empty string
-
- if (staticTextItem || editTextItem)
- {
- GetDialogItemText(handle, outText);
- }
-
- if (controlItem)
- {
- ControlHandle controlHandle = (ControlHandle) handle;
-
- GetControlTitle(controlHandle, outText);
- }
- }
-
- void DialogItem_SetText(DialogRef inDialog, DialogItemIndex inItem, const StringPtr inText)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetText inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetText inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetText inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetText inItem <= 0");
- DUASSERT_RET(inText != nil, "DialogItem_SetText inText == nil");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- Boolean staticTextItem = isStaticTextType(type);
- Boolean editTextItem = isEditTextType(type);
- Boolean controlItem = isControlType(type);
-
- DUASSERT_RET(staticTextItem || editTextItem || controlItem, "DialogItem_SetText item wrong type");
- DUASSERT_RET(handle != nil, "DialogItem_SetText item handle = nil");
- DUASSERT_RET(*handle != nil, "DialogItem_SetText item handle was purged");
-
- if (staticTextItem || editTextItem)
- {
- SetDialogItemText(handle, inText);
- }
-
- if (controlItem)
- {
- ControlHandle controlHandle = (ControlHandle) handle;
-
- SetControlTitle(controlHandle, inText);
- }
- }
-
- void DialogItem_SetTextQuietly(DialogRef inDialog, DialogItemIndex inItem, const StringPtr inText)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetTextQuietly inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetTextQuietly inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetTextQuietly inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetTextQuietly inItem <= 0");
- DUASSERT_RET(inText != nil, "DialogItem_SetTextQuietly inText == nil");
-
- Str255 oldText;
-
- DialogItem_GetText(inDialog, inItem, oldText);
-
- // if strings are identical don't set
- // Boolean EqualString(str1, str2, caseSensitive, diacSensitive);
- if (EqualString(inText, oldText, true, true)) { return; }
-
- DialogItem_SetText(inDialog, inItem, inText);
- }
-
-
- /*
- *
- * functions for working with groups of radio buttons
- *
- */
-
- void DialogItem_SetRadioButtonGroup(DialogRef inDialog, DialogItemIndex inFirstItem, DialogItemIndex inLastItem, DialogItemIndex inNewItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetRadioButtonGroup inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetRadioButtonGroup inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inFirstItem, "DialogItem_SetRadioButtonGroup inFirstItem > CountDITL(inDialog)");
- DUASSERT_RET(inFirstItem > 0, "DialogItem_SetRadioButtonGroup inFirstItem <= 0");
- DUASSERT_RET(CountDITL(inDialog) >= inLastItem, "DialogItem_SetRadioButtonGroup inLastItem > CountDITL(inDialog)");
- DUASSERT_RET(inLastItem > 0, "DialogItem_SetRadioButtonGroup inLastItem <= 0");
- DUASSERT_RET(inNewItem >= inFirstItem, "DialogItem_SetRadioButtonGroup inNewItem >= inFirstItem");
- DUASSERT_RET(inNewItem <= inLastItem, "DialogItem_SetRadioButtonGroup inNewItem <= inLastItem");
-
- DialogItemIndex itr;
-
- for(itr = inFirstItem; itr <= inLastItem; itr++)
- {
- if (itr == inNewItem)
- {
- DialogItem_SetValueQuietly(inDialog, itr, 1);
- }
- else
- {
- DialogItem_SetValueQuietly(inDialog, itr, 0);
- }
- }
- }
-
- short DialogItem_GetRadioButtonGroup(DialogRef inDialog, DialogItemIndex inFirstItem, DialogItemIndex inLastItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "DialogItem_GetRadioButtonGroup inDialog == nil" , inFirstItem);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "DialogItem_GetRadioButtonGroup inDialog is not a dialog" , inFirstItem);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inFirstItem, "DialogItem_GetRadioButtonGroup inFirstItem > CountDITL(inDialog)" , inFirstItem);
- DUASSERT_RETVAL(inFirstItem > 0, "DialogItem_GetRadioButtonGroup inFirstItem <= 0" , inFirstItem);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inLastItem, "DialogItem_GetRadioButtonGroup inLastItem > CountDITL(inDialog)" , inFirstItem);
- DUASSERT_RETVAL(inLastItem > 0, "DialogItem_GetRadioButtonGroup inLastItem <= 0" , inFirstItem);
-
- DialogItemIndex itr;
-
- for(itr = inFirstItem; itr <= inLastItem; itr++)
- {
- ControlValue value = DialogItem_GetValue(inDialog, itr);
-
- if (value) break;
- }
-
- DUASSERT_RETVAL(itr <= inLastItem, "DialogItem_GetRadioButtonGroup could not find a set button", inLastItem);
-
- return itr;
- }
-
-
- /*
- *
- * Getting/Setting dialog item min/max/value
- *
- */
-
- ControlValue DialogItem_GetValue(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "DialogItem_GetValue inDialog == nil", 0);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "DialogItem_GetValue inDialog is not a dialog", 0);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inItem, "DialogItem_GetValue inItem > CountDITL(inDialog)", 0);
- DUASSERT_RETVAL(inItem > 0, "DialogItem_GetValue inItem <= 0", 0);
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RETVAL(isControlType(type), "DialogItem_GetValue not a control item", 0);
- DUASSERT_RETVAL(handle != nil, "DialogItem_GetValue handle == nil", 0);
- DUASSERT_RETVAL(*handle != nil, "DialogItem_GetValue handle was purged", 0);
-
- ControlValue item_value = 0;
- ControlHandle controlHandle = (ControlHandle) handle;
-
- item_value = GetControlValue(controlHandle);
-
- return item_value;
- }
-
- ControlValue DialogItem_GetMin(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "DialogItem_GetMin inDialog == nil", 0);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "DialogItem_GetMin inDialog is not a dialog", 0);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inItem, "DialogItem_GetMin inItem > CountDITL(inDialog)", 0);
- DUASSERT_RETVAL(inItem > 0, "DialogItem_GetMin inItem <= 0", 0);
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RETVAL(isControlType(type), "DialogItem_GetMin not a control item", 0);
- DUASSERT_RETVAL(handle != nil, "DialogItem_GetMin handle == nil", 0);
- DUASSERT_RETVAL(*handle != nil, "DialogItem_GetMin handle was purged", 0);
-
- short item_min = 0;
- ControlHandle controlHandle = (ControlHandle) handle;
-
- item_min = GetControlMinimum(controlHandle);
-
- return item_min;
- }
-
- ControlValue DialogItem_GetMax(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "DialogItem_GetMax inDialog == nil", 0);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "DialogItem_GetMax inDialog is not a dialog", 0);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inItem, "DialogItem_GetMax inItem > CountDITL(inDialog)", 0);
- DUASSERT_RETVAL(inItem > 0, "DialogItem_GetMax inItem <= 0", 0);
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RETVAL(isControlType(type), "DialogItem_GetMax not a control item", 0);
- DUASSERT_RETVAL(handle != nil, "DialogItem_GetMax handle == nil", 0);
- DUASSERT_RETVAL(*handle != nil, "DialogItem_GetMax handle was purged", 0);
-
- ControlValue item_max = 0;
- ControlHandle controlHandle = (ControlHandle) handle;
-
- item_max = GetControlMaximum(controlHandle);
-
- return item_max;
- }
-
- void DialogItem_SetValue(DialogRef inDialog, DialogItemIndex inItem, ControlValue value)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetValue inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetValue inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetValue inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetValue inItem <= 0");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RET(isControlType(type), "DialogItem_SetValue not a control item");
- DUASSERT_RET(handle != nil, "DialogItem_SetValue handle == nil");
- DUASSERT_RET(*handle != nil, "DialogItem_SetValue handle was purged");
-
- ControlHandle controlHandle = (ControlHandle) handle;
-
- SetControlValue(controlHandle, value);
- }
-
- void DialogItem_SetValueQuietly(DialogRef inDialog, DialogItemIndex inItem, ControlValue value)
- {
- ControlValue old_value = DialogItem_GetValue(inDialog, inItem);
-
- if (old_value != value) { DialogItem_SetValue(inDialog, inItem, value); }
- }
-
- void DialogItem_SetMin(DialogRef inDialog, DialogItemIndex inItem, ControlValue min)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetMin inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetMin inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetMin inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetMin inItem <= 0");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RET(isControlType(type), "DialogItem_SetMin not a control item");
- DUASSERT_RET(handle != nil, "DialogItem_SetMin handle == nil");
- DUASSERT_RET(*handle != nil, "DialogItem_SetMin handle was purged");
-
- ControlHandle controlHandle = (ControlHandle) handle;
-
- SetControlMinimum(controlHandle, min);
- }
-
- void DialogItem_SetMax(DialogRef inDialog, DialogItemIndex inItem, ControlValue max)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetMax inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetMax inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetMax inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetMax inItem <= 0");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- DUASSERT_RET(isControlType(type), "DialogItem_SetMax not a control item");
- DUASSERT_RET(handle != nil, "DialogItem_SetMax handle == nil");
- DUASSERT_RET(*handle != nil, "DialogItem_SetMax handle was purged");
-
- ControlHandle controlHandle = (ControlHandle) handle;
-
- SetControlMaximum(controlHandle, max);
- }
-
-
- /*
- *
- * Get/Set DialogItemIndex rect
- *
- */
-
- void DialogItem_GetRect(DialogRef inDialog, DialogItemIndex inItem, Rect *outItemRect)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_GetRect inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_GetRect inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_GetRect inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_GetRect inItem <= 0");
- DUASSERT_RET(outItemRect != nil, "DialogItem_GetRect outItemRect == nil");
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- *outItemRect = rect;
- }
-
- void DialogItem_SetRect(DialogRef inDialog, DialogItemIndex inItem, const Rect *inItemRect)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetRect inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetRect inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetRect inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetRect inItem <= 0");
-
- DialogItemType type;
- Handle handle;
- Rect oldRect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &oldRect);
- SetDialogItem(inDialog, inItem, type, handle, inItemRect);
-
- // if this is a control offset the control rect as well
- if (isControlType(type))
- {
- DUASSERT_RET(handle != nil, "DialogItem_SetRect item was control but handle was nil");
-
- ControlHandle control = (ControlHandle) handle;
- Rect controlRect = (*control)->contrlRect;
-
- MoveControl(control, inItemRect->left, inItemRect->top);
-
- SizeControl(control, (inItemRect->right - inItemRect->left),
- (inItemRect->bottom - inItemRect->top));
- }
- }
-
- void DialogItem_OffsetRect(DialogRef inDialog, DialogItemIndex inItem, short inDeltaH, short inDeltaV)
- {
- DUASSERT_RET(inDialog != nil, "OffestDialogItemRect inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "OffestDialogItemRect inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "OffestDialogItemRect inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "OffestDialogItemRect inItem <= 0");
-
- DialogItem_DeltaRect(inDialog, inItem, inDeltaV, inDeltaH, inDeltaV, inDeltaH);
- }
-
- void DialogItem_DeltaRect(DialogRef inDialog, DialogItemIndex inItem, short inTop, short inLeft, short inBottom, short inRight)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_DeltaRect inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_DeltaRect inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_DeltaRect inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_DeltaRect inItem <= 0");
-
- Rect rect;
-
- DialogItem_GetRect(inDialog, inItem, &rect);
-
- rect.top += inTop;
- rect.left += inLeft;
- rect.bottom += inBottom;
- rect.right += inRight;
-
- DialogItem_SetRect(inDialog, inItem, &rect);
- }
-
- short DialogItem_GetWidth(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "DialogItem_GetWidth inDialog == nil", 0);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "DialogItem_GetWidth inDialog is not a dialog",0);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inItem, "DialogItem_GetWidth inItem > CountDITL(inDialog)", 0);
- DUASSERT_RETVAL(inItem > 0, "DialogItem_GetWidth inItem <= 0", 0);
-
- Rect rect;
- short width;
-
- DialogItem_GetRect(inDialog, inItem, &rect);
-
- width = rect.right - rect.left;
-
- return width;
- }
-
- /*
- *
- * validate/invalidate
- *
- *
- */
-
- void DialogItem_Invalidate(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_Invalidate inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_Invalidate inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_Invalidate inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_Invalidate inItem <= 0");
-
- Rect rect;
- GWorldState saved_gworld(inDialog); // stack based class
-
- DialogItem_GetRect(inDialog, inItem, &rect);
- InvalRect(&rect);
- }
-
- void DialogItem_Valididate(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_Valididate inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_Valididate inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_Valididate inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_Valididate inItem <= 0");
-
- Rect rect;
- GWorldState saved_gworld(inDialog); // stack based class
-
- DialogItem_GetRect(inDialog, inItem, &rect);
- ValidRect(&rect);
- }
-
- void DialogItem_Show(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_Show inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_Show inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_Show inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_Show inItem <= 0");
-
- ShowDialogItem(inDialog, inItem);
- }
-
- void DialogItem_Hide(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_Hide inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_Hide inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_Hide inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_Hide inItem <= 0");
-
- HideDialogItem(inDialog, inItem);
- }
-
- DialogItemType DialogItem_GetType(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RETVAL(inDialog != nil, "DialogItem_SetType inDialog == nil",nil);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "DialogItem_SetType inDialog is not a dialog",nil);
- DUASSERT_RETVAL(CountDITL(inDialog) >= inItem, "DialogItem_SetType inItem > CountDITL(inDialog)",nil);
- DUASSERT_RETVAL(inItem > 0, "DialogItem_SetType inItem <= 0",nil);
-
- DialogItemType type;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &type, &handle, &rect);
-
- return type;
- }
-
- void DialogItem_SetType(DialogRef inDialog, DialogItemIndex inItem, DialogItemType inType)
- {
- DUASSERT_RET(inDialog != nil, "DialogItem_SetType inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "DialogItem_SetType inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "DialogItem_SetType inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem > 0, "DialogItem_SetType inItem <= 0");
-
- DialogItemType oldType;
- Handle handle;
- Rect rect;
-
- GetDialogItem(inDialog, inItem, &oldType, &handle, &rect);
- SetDialogItem(inDialog, inItem, inType, handle, &rect);
- }
-
- // getting and setting the default item
- DialogItemIndex Dialog_GetDefaultItem(DialogRef inDialog)
- {
- DUASSERT_RETVAL(inDialog != nil, "Dialog_SetDefaultItem inDialog == nil", 0);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "Dialog_GetDefaultItem inDialog is not a dialog", 0);
-
- DialogItemIndex defaultItem;
-
- defaultItem = GetDialogDefaultItem(inDialog);
-
- return defaultItem;
- }
-
- DialogItemIndex Dialog_GetCancelItem(DialogRef inDialog)
- {
- DUASSERT_RETVAL(inDialog != nil, "Dialog_GetCancelItem inDialog == nil", 0);
- DUASSERT_RETVAL(isDialogWindow(inDialog), "Dialog_GetCancelItem inDialog is not a dialog", 0);
-
- DialogItemIndex cancelItem;
-
- cancelItem = GetDialogCancelItem(inDialog);
-
- return cancelItem;
- }
-
- void Dialog_SetDefaultItem(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "Dialog_SetDefaultItem inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "Dialog_SetDefaultItem inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "Dialog_SetDefaultItem inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem >= 0, "Dialog_SetDefaultItem inItem < 0");
-
- SetDialogDefaultItem(inDialog, inItem);
- }
-
- void Dialog_SetCancelItem(DialogRef inDialog, DialogItemIndex inItem)
- {
- DUASSERT_RET(inDialog != nil, "Dialog_SetCancelItem inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "Dialog_SetCancelItem inDialog is not a dialog");
- DUASSERT_RET(CountDITL(inDialog) >= inItem, "Dialog_SetCancelItem inItem > CountDITL(inDialog)");
- DUASSERT_RET(inItem >= 0, "Dialog_SetCancelItem inItem < 0");
-
- SetDialogCancelItem(inDialog, inItem);
- }
-
- void Dialog_SetTracksCursor(DialogRef inDialog, Boolean tracks)
- {
- DUASSERT_RET(inDialog != nil, "Dialog_SetTrackCursor inDialog == nil");
- DUASSERT_RET(isDialogWindow(inDialog), "Dialog_SetTrackCursor inDialog is not a dialog");
-
- SetDialogTracksCursor(inDialog, tracks);
- }
-
- void Window_Validate(WindowRef inWindow)
- {
- DUASSERT_RET(inWindow != nil, "Window_Validate inWindow == nil");
-
- GWorldState savedGWorld(inWindow); // stack based class
- CGrafPtr windowPort = GetWindowPort(inWindow);
- Rect bounds = windowPort->portRect;
-
- ValidRect(&bounds);
- }
-
- void Window_Invalidate(WindowRef inWindow)
- {
- DUASSERT_RET(inWindow != nil, "Window_Validate inWindow == nil");
-
- GWorldState savedGWorld(inWindow); // stack based class
- CGrafPtr windowPort = GetWindowPort(inWindow);
- Rect bounds = windowPort->portRect;
-
- InvalRect(&bounds);
- }
-
- void GScForeColor_Set(GScGrayRamp color)
- {
- DUASSERT_RET(color >= GScRampWhite, "GScForeColor_Set color to small");
- DUASSERT_RET(color <= GScRampBlack, "GScForeColor_Set color to large");
-
- UInt16 theGrayColor = (0x1111) * (0xf - color);
- RGBColor newForeColor = {theGrayColor, theGrayColor, theGrayColor};
-
- RGBForeColor(&newForeColor);
- }
-
- void GScBackColor_Set(GScGrayRamp color)
- {
- DUASSERT_RET(color >= GScRampWhite, "GScBackColor_Set color to small");
- DUASSERT_RET(color <= GScRampBlack, "GScBackColor_Set color to large");
-
- UInt16 theGrayColor = (0x1111) * (0xf - color);
- RGBColor newForeColor = {theGrayColor, theGrayColor, theGrayColor};
-
- RGBBackColor(&newForeColor);
- }
-
- void GScTopLeft_Draw(const Rect *r, GScGrayRamp inColor)
- {
- QDColorState stackColorSaver; // saves and restore color w/ stack based object
- QDPenState stackPenSaver; // saves and restore pen w/ stack based object
- QDPenState::Clear(); // clear the pen state
-
- GScForeColor_Set(inColor);
-
- MoveTo(r->left, r->top);
- LineTo(r->right - 2, r->top);
-
- MoveTo(r->left, r->top);
- LineTo(r->left, r->bottom -2);
- }
-
- void GScBotRight_Draw(const Rect *r, GScGrayRamp inColor)
- {
- QDColorState stackColorSaver; // saves and restore color w/ stack based object
- QDPenState stackPenSaver; // saves and restore pen w/ stack based object
- QDPenState::Clear(); // clear the pen state
-
- GScForeColor_Set(inColor);
-
- MoveTo(r->right - 1, r->bottom - 1);
- LineTo(r->right - 1, r->top + 1);
-
- MoveTo(r->right - 1, r->bottom - 1);
- LineTo(r->left + 1, r->bottom - 1);
- }
-
- void GScGroupBox_PrimarySimple_Draw(const Rect *r, GScActiveType active)
- {
- QDColorState stackColorSaver; // saves and restore color w/ stack based object
- QDPenState stackPenSaver; // saves and restore pen w/ stack based object
- QDPenState::Clear(); // clear the pen state
-
- if (active) { GScForeColor_Set(GScRamp7); }
- else { GScForeColor_Set(GScRamp4); }
-
- MoveTo(r->left, r->top);
- LineTo(r->right - 2, r->top);
- LineTo(r->right - 2, r->bottom - 2);
- LineTo(r->left, r->bottom - 2);
- LineTo(r->left, r->top);
-
- if (active) { GScForeColor_Set(GScRampWhite); }
- else { GScForeColor_Set(GScRampBG); } // background color
-
- MoveTo(r->left + 1, r->top + 1);
- LineTo(r->right - 3, r->top + 1);
-
- MoveTo(r->left + 1, r->top + 1);
- LineTo(r->left + 1, r->bottom - 3);
-
- MoveTo(r->right - 1, r->bottom - 1);
- LineTo(r->right - 1, r->top + 1);
-
- MoveTo(r->right - 1, r->bottom - 1);
- LineTo(r->left + 1, r->bottom - 1);
- }
-
- void GScGroupBox_PrimaryNamed_Draw(const Rect *r, const Str255 string, GScActiveType active)
- {
- QDColorState stackColorSaver; // saves and restore color w/ stack based object
- QDPenState stackPenSaver; // saves and restore pen w/ stack based object
- QDPenState::Clear(); // clear the pen state
-
- if (active) { GScForeColor_Set(GScRamp7); }
- else { GScForeColor_Set(GScRamp4); }
-
- MoveTo(r->left, r->top);
- LineTo(r->left + 8, r->top);
-
- // leave a small border around string (and offset baseline down one pixel)
- if (active) { GScForeColor_Set(GScRampBlack); }
- else { GScForeColor_Set(GScRamp7); }
-
- Move(2, 1);
- DrawString(string);
- Move(1, -1);
-
- Point rightEdgeText;
- GetPen (&rightEdgeText);
-
- if (active) { GScForeColor_Set(GScRamp7); }
- else { GScForeColor_Set(GScRamp4); }
-
- // draw first rectangle
- LineTo(r->right - 2, r->top);
- LineTo(r->right - 2, r->bottom - 2);
- LineTo(r->left, r->bottom - 2);
- LineTo(r->left, r->top);
-
- if (active) { GScForeColor_Set(GScRampWhite); }
- else { GScForeColor_Set(GScRampBG); }
-
- MoveTo(r->left + 1, r->top + 1);
- LineTo(r->left + 8, r->top + 1);
- MoveTo(rightEdgeText.h, r->top + 1);
- LineTo(r->right - 3, r->top + 1);
-
- MoveTo(r->left + 1, r->top + 1);
- LineTo(r->left + 1, r->bottom - 3);
-
- MoveTo(r->right - 1, r->bottom - 1);
- LineTo(r->right - 1, r->top + 1);
-
- MoveTo(r->right - 1, r->bottom - 1);
- LineTo(r->left + 1, r->bottom - 1);
- }
-
- void GScGroupBox_SecondarySimple_Draw(const Rect *r, GScActiveType active)
- {
- GScGrayRamp topLeftColor;
- GScGrayRamp botRightColor;
-
- // top & left
- if (active) { topLeftColor = GScRamp7; }
- else { topLeftColor = GScRamp4; }
-
- GScTopLeft_Draw(r, topLeftColor);
-
- // bottom and right
- if (active) { botRightColor = GScRampWhite; }
- else { botRightColor = GScRamp4; }
-
- GScBotRight_Draw(r, botRightColor);
- }
-
- void GScGroupBox_SecondaryNamed_Draw(const Rect *r, const Str255 string, GScActiveType active)
- {
- QDColorState stackColorSaver; // saves and restore color w/ stack based object
- QDPenState stackPenSaver; // saves and restore pen w/ stack based object
- QDPenState::Clear(); // clear the pen state
-
- if (active) { GScForeColor_Set(GScRamp7); }
- else { GScForeColor_Set(GScRamp4); }
-
- MoveTo(r->left, r->top);
- LineTo(r->left + 8, r->top);
-
- // leave a small border around string (and offset baseline down one pixel)
- if (active) { GScForeColor_Set(GScRampBlack); }
- else { GScForeColor_Set(GScRamp7); }
-
- Move(2, 1);
- DrawString(string);
- Move(1, -1);
-
- if (active) { GScForeColor_Set(GScRamp7); }
- else { GScForeColor_Set(GScRamp4); }
-
- LineTo(r->right - 2, r->top);
-
- MoveTo(r->left, r->top);
- LineTo(r->left, r->bottom -2);
-
- if (active) { GScForeColor_Set(GScRampWhite); }
- else { GScForeColor_Set(GScRamp4); }
-
- // bottom & right side
- MoveTo(r->right - 1, r->bottom - 1);
- LineTo(r->right - 1, r->top + 1);
-
- MoveTo(r->right - 1, r->bottom - 1);
- LineTo(r->left + 1, r->bottom - 1);
- }
-
- void GScTextEntryFrame_Draw(const Rect *r, GScActiveType active)
- {
- QDColorState stackColorSaver; // saves and restore color w/ stack based object
- QDPenState stackPenSaver; // saves and restore pen w/ stack based object
- QDPenState::Clear(); // clear the pen state
-
- Rect insetRect = *r;
- InsetRect(&insetRect, 1, 1);
-
- if (active)
- {
- GScTopLeft_Draw(r, GScRamp5);
- GScBotRight_Draw(r, GScRampWhite);
-
- GScForeColor_Set(GScRampBlack);
- FrameRect(&insetRect);
- }
- else
- {
- GScForeColor_Set(GScRampBG);
- FrameRect(r);
-
- GScForeColor_Set(GScRamp10);
- FrameRect(&insetRect);
- }
- }
-
-
-
-
- /****************************************** EASY COPY BITS FUNCTIONS ******************************************/
-
- /*
- *
- * CopyBitsLite
- *
- * Copy bits from source to dest, does not colorize and sets port to the dst before
- * it does the copy.
- *
- */
-
- void CopyBitsLite(CGrafPtr src, CGrafPtr dst, const Rect *srcRect, const Rect *dstRect)
- {
- DUASSERT_RET(src != nil, "CopyBitsLite src was nil");
- DUASSERT_RET(dst != nil, "CopyBitsLite dst was nil");
-
- GrafPtr srcGrafPort = (GrafPtr) src; // casting of our CGrafPtrs to GrafPtr
- GrafPtr dstGrafPort = (GrafPtr) dst;
-
- GWorldState stack_port_saver(dstGrafPort); // set the port to the dest and save old port
-
- {
- QDColorState stack_color_saver; // save old colors
- QDColorState::Clear(); // set fore/back color to black/white
-
- CopyBits(&srcGrafPort->portBits, &dstGrafPort->portBits, srcRect, dstRect, srcCopy, nil);
- DUASSERT(QDErr() == noErr, "CopyBits gave an error inside CopyBitsLite");
- }
- }
-
- void CopyBitsLiteWithColor(CGrafPtr src, CGrafPtr dst, const Rect *srcRect, const Rect *dstRect, const RGBColor *inColor)
- {
- DUASSERT_RET(src != nil, "CopyBitsLiteWithColor src was nil");
- DUASSERT_RET(dst != nil, "CopyBitsLiteWithColor dst was nil");
-
- GrafPtr srcGrafPort = (GrafPtr) src; // casting of our CGrafPtrs to GrafPtr
- GrafPtr dstGrafPort = (GrafPtr) dst;
-
- GWorldState stack_port_saver(dstGrafPort); // set the port to the dest and save old port
-
- {
- QDColorState stack_color_saver; // save old colors
-
- RGBForeColor(inColor); // set fore/back color to in color/white
- BackColor(whiteColor);
-
- CopyBits(&srcGrafPort->portBits, &dstGrafPort->portBits, srcRect, dstRect, srcCopy, nil);
- DUASSERT(QDErr() == noErr, "CopyBits gave an error inside CopyBitsLiteWithColor");
- }
- }
-
- QDColorState::QDColorState()
- {
- // color
- ::SaveFore(&mForegroundColor);
- ::SaveBack(&mBackgroundColor);
- }
-
-
- QDColorState::~QDColorState()
- {
- // color
- ::RestoreFore(&mForegroundColor);
- ::RestoreBack(&mBackgroundColor);
- }
-
- void
- QDColorState::Clear()
- {
- ::ForeColor(blackColor);
- ::BackColor(whiteColor);
- }
-
- QDTextState::QDTextState()
- {
- GrafPtr port;
- GetPort(&port);
-
- mFontID = port->txFont;
- mFace = port->txFace;
- mMode = port->txMode;
- mSize = port->txSize;
- }
-
-
- QDTextState::~QDTextState()
- {
- ::TextFont(mFontID);
- ::TextFace(mFace);
- ::TextMode(mMode);
- ::TextSize(mSize);
- }
-
- void QDTextState::Clear()
- {
- ::TextFont(systemFont);
- ::TextFace(0);
- ::TextMode(srcOr);
- ::TextSize(0);
- }
-
- QDPenState::QDPenState(void)
- {
- ::GetPenState(&mPenState);
- }
-
- QDPenState::~QDPenState(void)
- {
- ::SetPenState(&mPenState);
- }
-
- void QDPenState::Clear(void)
- {
- ::MoveTo(0,0);
- ::PenNormal();
- }
-
- GWorldState::GWorldState(void)
- {
- GetGWorld(&mPort, &mGDH);
- }
-
- GWorldState::GWorldState(GrafPtr inNewPort)
- {
- GetGWorld(&mPort, &mGDH);
-
- if (isColorPort(inNewPort))
- {
- SetGWorld((CGrafPtr) inNewPort, nil);
- }
- else
- {
- SetPort (inNewPort);
- }
- }
-
- GWorldState::~GWorldState()
- {
- SetGWorld(mPort, mGDH);
- }
-
- #if __MWERKS__
- #pragma optimize_for_size reset
- #endif
-